package com.luhy.controller;

import com.luhy.pojo.Order;
import com.luhy.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/add/{course}/{cost}")
    public String addOrder(@PathVariable String course,@PathVariable double cost, Model model) {
        Order order = new Order();
        order.setCourse(course);
        order.setCost(cost);
        Order order2 = orderService.insert(order);
        model.addAttribute(order2);
        return "pay";
    }

    @GetMapping("/list")
    public String queryOrders(Model model) {
        List<Order> orders = orderService.selectAll();
        model.addAttribute("list", orders);
        return "orderList";
    }

    @GetMapping("/pay/{orderNo}")
    public String pay(@PathVariable String orderNo) {
        orderService.pay(orderNo);
        return "redirect:/order/list";
    }
}
